﻿package dut.ir.lxb.weibo.util;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Properties;
import java.util.Random;

/**
 * 配置文件
 * @author Administrator
 *
 */
public class SpiderConfig
{
	public static Properties properties;
	
	public static final String rootDirectory = "./";
	
	public static String emojPattern = "[\ud83c\udc00-\ud83c\udfff]|[\ud83d\udc00-\ud83d\udfff]|[\u2600-\u27ff]";
	
	
	
	static
	{
		properties = new Properties();
		try
		{
			properties.load(new InputStreamReader(new FileInputStream(rootDirectory + "config/weibospider.properties"), "UTF-8"));
		}
		catch (FileNotFoundException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		catch (IOException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
	}
	
	public static String getDomid()
	{
		return properties.getProperty("domid", "Pl_Third_App__159");
	}
	
	public static String getBaiduJsFile()
	{
		return properties.getProperty("baidujsfile");
	}
	
	public static String getAccountType()
	{
		return properties.getProperty("accounttype");
	}
	
	public static String getParameterUrl()
	{
		return properties.getProperty("parameterurl");
	}
	
	public static String getLoginUrl()
	{
		return properties.getProperty("loginurl");
	}
	
	public static String getUserName()
	{
		return properties.getProperty("username");
	}
	
	public static String getPassword()
	{
		return properties.getProperty("password");
	}
	
	public static String getSaveDirectory()
	{
		return properties.getProperty("savedirectory");
	}
	public static String getUserInfoEncoding()
	{
		return properties.getProperty("userinfoencoding", "utf-8");
	}
	
	public static int getWeiboCountPerpage()
	{
		String countStr = properties.getProperty("weiboperpage", "45");
		return Integer.parseInt(countStr);
	}
	
	public static String getWeiboEncoding()
	{
		return properties.getProperty("weiboencoding", "utf-8");
	}
	
	public static String getCommentUrl()
	{
		return properties.getProperty("commenturl");
	}
	
	public static String getForwardUrl()
	{
		return properties.getProperty("forwardurl");
	}
	
	public static String getLikeUrl()
	{
		return properties.getProperty("likeurl");
	}
	
	public static String getFollowUrl()
	{
		return properties.getProperty("followurl");
	}
	
	public static int getMaxFollowCount()
	{
		String valueStr = properties.getProperty("maxfollowcount", "200");
		int count = Integer.parseInt(valueStr);
		
		return count;
	}
	
	public static int getMaxFollowPerpage()
	{
		String valueStr = properties.getProperty("maxfollowperpage", "20");
		int count = Integer.parseInt(valueStr);
		
		return count;
	}
	
	public static String getLogoutUrl()
	{
		return properties.getProperty("logouturl");
	}
	
	public static String getFansUrl()
	{
		return properties.getProperty("fansurl");
	}
	
	public static String getOutputEncoding()
	{
		return properties.getProperty("outputencoding", "utf-8");
	}
	
	public static String getRootUid()
	{
		return properties.getProperty("rootuid", "1937618377");
	}
	
	public static boolean isLikeNeeded()
	{
		String strValue = properties.getProperty("islike", "true");
		return Boolean.parseBoolean(strValue);
	}
	
	public static boolean isForwardNeeded()
	{
		String strValue = properties.getProperty("isforward", "true");
		return Boolean.parseBoolean(strValue);
	}
	
	public static boolean isCommentNeeded()
	{
		String strValue = properties.getProperty("iscomment", "true");
		return Boolean.parseBoolean(strValue);
	}
	
	public static boolean isLikeUserNeeded()
	{
		String strValue = properties.getProperty("likeuser", "true");
		return Boolean.parseBoolean(strValue);
	}
	
	public static boolean isCommentUserNeeded()
	{
		String strValue = properties.getProperty("comment", "true");
		return Boolean.parseBoolean(strValue);
	}
	
	public static boolean isForwardUserNeeded()
	{
		String strValue = properties.getProperty("forwarduser", "true");
		return Boolean.parseBoolean(strValue);
	}
	
	public static String getWeiboUrl()
	{
		return properties.getProperty("weibourl");
	}
	
	public static String getWeiboDirectory()
	{
		return properties.getProperty("weibodirectory", "./weibo/");
	}
	
	public static String getDefaultConnectionPool()
	{
		return properties.getProperty("defaultpool", "DUTIRWeiboPlatform");
	}
	
	
	
	
	
	public static String getEventEncoding()
	{
		return properties.getProperty("eventencoding", "utf-8");
	}
	
	
	public static int getMaxEventPageCount()
	{
		String value = properties.getProperty("maxeventpage", "2");
		return Integer.parseInt(value);
	}
	
	public static int getMaxEventCount()
	{
		String value = properties.getProperty("maxeventcount", "10");
		return Integer.parseInt(value);
	}
	
	/**
	 * 每次请求之后的等待时间，随机
	 * @return 等待时间
	 */
	public static int getWaitTime()
	{
		String value = properties.getProperty("waittime", "1000");
		int configWaitTime = Integer.parseInt(value);
		Random rd = new Random(System.currentTimeMillis());
		return rd.nextInt(configWaitTime);
	}
	
	public static String getUidsFile()
	{
		String value = properties.getProperty("uidfile", rootDirectory + "config/uids.txt");
		return value;
	}
	
	public static int getMinForwardNumber()
	{
		String value = properties.getProperty("minforwardnum", "10");
		return Integer.parseInt(value);
		
	}
	
	public static int getStratEventIndex()
	{
		String value = properties.getProperty("starteventindex", "0");
		return Integer.parseInt(value);
	}
	
	public static int getMaxPageCount()
	{
		String value = properties.getProperty("maxpagecount", "100");
		return Integer.parseInt(value);
	}
	
	public static double getForwardCountThreshold()
	{
		String value = properties.getProperty("forwardcountthreshold", "0.8");
		return Double.parseDouble(value);
	}
	
	public static int getForwardCountPerpage()
	{
		String value = properties.getProperty("forwardcountperpage", "20");
		return Integer.parseInt(value);
	}
	
	public static int getCommentCountPerpage()
	{
		String value = properties.getProperty("commentcountperpage", "18");
		return Integer.parseInt(value);
	}
	
	public static int getLikeCountPerpage()
	{
		String value = properties.getProperty("likecountperpage", "30");
		return Integer.parseInt(value);
	}
	
	public static int getLatestActionWeiboCount()
	{
		String value = properties.getProperty("latestactionweibo", "50");
		return Integer.parseInt(value);
	}
	
	public static int getSkipActionWeiboCount()
	{
		String value = properties.getProperty("skipactionweibo", "10000");
		return Integer.parseInt(value);
	}
	
}
